package com.library.service.implementation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import com.library.entities.Account;
import com.library.service.account.AccountService;
import com.library.service.implementation.account.SecurityAccount;

public class LibraryUserDetailsService implements UserDetailsService{
	
	@Autowired
	private AccountService accountService;
	
	@Override
	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException {
		Account account = accountService.findAccountByUsername(username);
		if(account == null){
			throw new UsernameNotFoundException("UserName "+username+" not found");
		}
		return new SecurityAccount(account);
	}

}
